

/*
* Copyright @ 2017 com.iflysse.trains
* crm 下午4:21:46
* All right reserved.
*
*/
	
package com.qf.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qf.dto.CrmDepartmentDto;
import com.qf.pojo.CrmDepartment;
import com.qf.pojo.PageBean;
import com.qf.service.CrmDepartmentService;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月24日 下午4:21:46
* @history:
* @version: v1.0

*/
@Controller
public class CrmDepartmentServlet {
	@Autowired
	@Qualifier("crmDepartmentService")
	private CrmDepartmentService cs;
	
	
	/**
	* @param cs the cs to set
	*/
	
	public void setCs(CrmDepartmentService cs) {
	
		this.cs = cs;
	}

    @RequestMapping("/addDepart.do")
	public ModelAndView addDepart(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv=new ModelAndView();
		String depName = request.getParameter("depName");
		CrmDepartment department = cs.findByName(depName);
		if(department==null){
	    department = new CrmDepartment();
		department.setDepName(depName); 
		cs.addDepartment(department);
		mv.setViewName("listDepart.do");
		}else{
			mv.addObject("msb", "该课程已存在");
			mv.setViewName("/pages/department/addOrEditDepartment.jsp");
		}
		
		return mv;
		
	}
    @RequestMapping("/listDepart.do")
	public ModelAndView listDepart(HttpServletRequest request,HttpServletResponse response){
    	ModelAndView mv=new ModelAndView();
    	String page_=request.getParameter("page");
    	int page=1;
    	int size=3;
    	if(page_!=null){
    		page=Integer.parseInt(page_);
    	}
    	PageBean pageBean = cs.findDepartmentByPage(page, size);
    	mv.addObject("pageBean", pageBean);
    	mv.setViewName("/pages/department/listDepartment.jsp");
    	return mv;
} 
    @RequestMapping("/preupdateDepart.do")
    public ModelAndView preupdateDepart(HttpServletRequest request,HttpServletResponse response){
    	ModelAndView mv = new ModelAndView();
    	String eid = request.getParameter("eid");
    	String depName=request.getParameter("depName");
    	mv.addObject("eid", eid);
    	mv.addObject("depName", depName);
    	mv.setViewName("/pages/department/editDepartment.jsp");
		return mv;
    	
    }
    @RequestMapping("/updateDepart.do")
    public ModelAndView updateDepart(HttpServletRequest request,HttpServletResponse response){
    	ModelAndView mv=new ModelAndView();
    	String depId_ = request.getParameter("depId");
    	String depName = request.getParameter("depName");
    	Long depId=Long.valueOf(depId_);
    	CrmDepartment department = cs.findbyID(depId);
    	department.setDepName(depName);
        cs.updateDepartment(department);
        mv.setViewName("listDepart.do");
		return mv;
    	
    }
 
  @RequestMapping("/AllDeparts.do")
    public @ResponseBody List<CrmDepartmentDto> allDeparts(HttpServletRequest request,HttpServletResponse response){
    	List<CrmDepartmentDto> deptList = cs.findAllDepartment();
		return deptList;
}
  @RequestMapping("/allDepart.do")
  public ModelAndView allDepart(HttpServletRequest request,HttpServletResponse response){
	  ModelAndView mv=new ModelAndView();
  	List<CrmDepartmentDto> deptList = cs.findAllDepartment();
		 mv.addObject("deptList", deptList);
		 mv.setViewName("/pages/staff/addStaff.jsp");
		return mv;
}

}	